//
//  ZFAuthorizeInfoViewController.m
//  HappilyLoan
//
//  Created by zainishenbian on 2017/3/24.
//  Copyright © 2017年 zongqingxiangqian. All rights reserved.
//

#import "ZFAuthorizeInfoViewController.h"
#import "ZFBindCardViewController.h"//绑定银行卡VC
#import "ZFFaceInfoViewController.h"
#import "ZFZMAuthorizeViewController.h"//芝麻信用VC
#import "ZFHeader.h"

@interface ZFAuthorizeInfoViewController ()

@property (nonatomic,strong) AnimatingView *animation;
@property (nonatomic,strong) AlertBoxView *alertV;

@end

@implementation ZFAuthorizeInfoViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"authorizeView"];
    self.navigationController.navigationBarHidden = NO;
    
    [_ZMButton setShadowWidth:2 shadowHeight:2 shadowColor:Main_Color1 radius:10];
    [ZFApplyInfoHttpRequest requestCheckZMAuthorizeStatusComplete:^(NSDictionary *dict) {
        
        if ([dict[@"code"] integerValue] == 1) {
            if ([dict[@"data"][@"zmxy_auth"] integerValue] == 1) {
                
                _SesameCreditStatuLabel.text = @"已授权";
//                _ZMButton.enabled = NO;
            }
        }
        
    } failureBlock:^(NSInteger failSign) {
        [_alertV appearAndDisappearAlertWithString:@"网络连接失败"];
    }];

}
- (void)viewWillDisappear:(BOOL)animated
{

    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"authorizeView"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"信息授权";

    _animation = [[AnimatingView alloc] init];
    
    _alertV = [[AlertBoxView alloc] init];
    [self.view addSubview:_alertV];

    //流量隐藏
    _operatorView.hidden = YES;
    _lineView.hidden = YES;
}
//芝麻授权
- (IBAction)SesameCreditClick:(id)sender {
    
//    UIButton *button = (UIButton *)sender;
    
    if ([_SesameCreditStatuLabel.text isEqualToString:@"未授权"]) {
        
        [ZFApplyInfoHttpRequest requestSesameCreditUrlSucessBlock:^(NSDictionary *dict) {
            
            if ([dict[@"is_alert"] integerValue] == 1) {
                
                [self showAlertView:dict[@"msg"]];
            }
            if ([dict[@"code"] integerValue] == 1) {
                
                ZFZMAuthorizeViewController *ZMVC = [ZFZMAuthorizeViewController new];
                ZMVC.ZMUrl = dict[@"data"][@"zmxy_url"];
                [self.navigationController pushViewController:ZMVC animated:YES];
            }
        } failureBlock:^(NSInteger failSign) {
            [_alertV appearAndDisappearAlertWithString:@"网络连接失败"];
        }];
    }
    else
    {
        NSLog(@"已授权");
    }
}
- (IBAction)operatorVerify:(id)sender {
}

- (IBAction)sureClick:(id)sender {
    
    if ([_SesameCreditStatuLabel.text isEqualToString:@"已授权"]) {
        
        ZFBindCardViewController *bindVC = [ZFBindCardViewController new];
        bindVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:bindVC animated:YES];
    }
    else
    {
        [_alertV appearAndDisappearAlertWithString:@"请授权"];
    }
}
#pragma mark ———— 返回
- (BOOL)navigationShouldPopOnBackButton
{
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [self.navigationController popToRootViewControllerAnimated:YES];

    if (delegate.isFirstEnterApp == YES) {
        
        delegate.isFirstEnterApp = NO;
        return NO;
    }
    return NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
